Added information about examples as libraries to the documentation
authorKalita Alexey <kalita.alexey@outlook.com>
Mon, 23 Jan 2017 08:45:11 +0000 (11:45 +0300)
committerKalita Alexey <kalita.alexey@outlook.com>
Mon, 23 Jan 2017 08:45:11 +0000 (11:45 +0300)
src/doc/guide.md
src/doc/manifest.md

index c26a830d7ca435b5906d6d83fa6bb01467b1819a..32ff74e8f7d5954b0ce13addc904e11bb127bcbe 100644 (file)
@@ -238,7 +238,7 @@ Cargo project:
 * The default executable file is `src/main.rs`.
 * Other executables can be placed in `src/bin/*.rs`.
 * Integration tests go in the `tests` directory (unit tests go in each file they're testing).
-* Example executable files go in the `examples` directory.
+* Examples go in the `examples` directory.
 * Benchmarks go in the `benches` directory.
 
 These are explained in more detail in the [manifest
index aebf1a28298cb105802aa0a4aaa0565b74aef6e0..5a61c741dd34b31cf25a3637869854da53a8ed16 100644 (file)
@@ -427,7 +427,7 @@ is a library, name the main source file `src/lib.rs`.
 Cargo will also treat any files located in `src/bin/*.rs` as executables.
 
 Your project can optionally contain folders named `examples`, `tests`, and
-`benches`, which Cargo will treat as containing example executable files,
+`benches`, which Cargo will treat as containing examples,
 integration tests, and benchmarks respectively.
 
 ```notrust
@@ -451,13 +451,19 @@ To structure your code after you've created the files and folders for your proje
 Files located under `examples` are example uses of the functionality provided by
 the library. When compiled, they are placed in the `target/examples` directory.
 
-They must compile as executables (with a `main()` function) and load in the
-library by using `extern crate <library-name>`. They are compiled when you run
+They may compile either as executables (with a `main()` function) or as libraries.
+They load in the library by using `extern crate <library-name>`. They are compiled when you run
 your tests to protect them from bitrotting.
 
-You can run individual examples with the command `cargo run --example
+You can run individual executable examples with the command `cargo run --example
 <example-name>`.
 
+Specify `crate-type` to make an example be compiled as a library:
+```toml
+[[example.example]]
+crate-type = ["staticlib"]
+```
+
 # Tests
 
 When you run `cargo test`, Cargo will: